/*
 * @Author: asdefwe 535294621@qq.com
 * @Date: 2024-03-03 20:40:57
 * @LastEditors: asdefwe 535294621@qq.com
 * @LastEditTime: 2024-05-19 23:34:46
 * @FilePath: \usb_-uart\User\st7735s.h
 * @Description: 
 * 
 * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. 
 */
#ifndef __ST7735_H
#define __ST7735_H

#include "main.h"



#define LCD_CS_HIGH         HAL_GPIO_WritePin(LCD_CS_GPIO_Port, LCD_CS_Pin, GPIO_PIN_SET);
#define LCD_CS_LOW			HAL_GPIO_WritePin(LCD_CS_GPIO_Port, LCD_CS_Pin, GPIO_PIN_RESET);

#define LCD_DC_HIGH         HAL_GPIO_WritePin(LCD_RS_GPIO_Port, LCD_RS_Pin, GPIO_PIN_SET);
#define LCD_DC_LOW			HAL_GPIO_WritePin(LCD_RS_GPIO_Port, LCD_RS_Pin, GPIO_PIN_RESET);


//LCD屏幕尺寸设置
#define DeviationX	26
#define DeviationY	1
#define Length  80
#define Width   160

//预设颜色
#define WHITE              0xFFFF
#define BLACK              0x0000      
#define BLUE            0x001F  
#define BRED            0XF81F
#define GRED                   0XFFE0
#define GBLUE                  0X07FF
#define RED                0xF800
#define MAGENTA            0xF81F
#define GREEN              0x07E0
#define CYAN               0x7FFF
#define YELLOW             0xFFE0
#define BROWN                  0XBC40 //棕色
#define BRRED                  0XFC07 //棕红色
#define GRAY                   0X8430 //灰色
#define DARKBLUE           0X01CF    //深蓝色
#define LIGHTBLUE       0X7D7C    //浅蓝色  
#define GRAYBLUE        0X5458 //灰蓝色
#define LIGHTGREEN      0X841F //浅绿色
#define LGRAY                  0XC618 //浅灰色(PANNEL),窗体背景色
#define LGRAYBLUE       0XA651 //浅灰蓝色(中间层颜色)
#define LBBLUE          0X2B12 //浅棕蓝色(选择条目的反色)
#define Silver			0XC618	// 银色


//根据MADCTL参数的帧数据写入方向
#define Normal                  (0x00 << 7 | 0x00 << 6 | 0x00 << 5)
#define Y_Mirror                (0x00 << 7 | 0x00 << 6 | 0x01 << 5)
#define X_Mirror                (0x00 << 7 | 0x01 << 6 | 0x00 << 5)
#define XY_Mirror               (0x00 << 7 | 0x01 << 6 | 0x01 << 5)
#define XY_Exchange             (0x01 << 7 | 0x00 << 6 | 0x00 << 5)
#define XY_Exchange_Y_Mirror    (0x01 << 7 | 0x00 << 6 | 0x01 << 5)
#define XY_Exchange_X_Mirror    (0x01 << 7 | 0x01 << 6 | 0x00 << 5)
#define XY_Exchange_XY_Mirror   (0x01 << 7 | 0x01 << 6 | 0x01 << 5)

//LCD垂直刷新方向控制
#define Vertical_Refresh_ToBottom   (0x00 << 4)
#define Vertical_Refresh_ToTOP      (0x01 << 4)

//LCD水平刷新方向控制
#define Horizontal_Refresh_ToRight   (0x00 << 2)
#define Horizontal_Refresh_ToLeft    (0x01 << 2)

//像素顺序控制
#define RGB     (0x00 << 3)
#define BGR     (0x01 << 3)


typedef struct{
    uint8_t Cover;              // 背景是否原界面
    uint8_t X;                  // 开始 x 位置
    uint8_t Y;                  // 开始 y 位置
    uint8_t fontsize;           // 字符尺寸大小
    unsigned short color;       // 画笔颜色
    unsigned short bkColor;     // 背景颜色
}lcd_t;



// 将8位值转换为5位、6位或5位（取决于是否需要）  
#define CONVERT5BITS(v) ((v) >> 3)  
#define CONVERT6BITS(v) ((v) >> 2)  


	
extern void Lcd_Init(void);

extern void LCD_Fill(int color);
extern void LCE_Fill_Memory(unsigned char XB, unsigned char YB, unsigned char XE, unsigned char YE, unsigned int memory);
extern void LCD_Fill_picture(unsigned short *pic);
extern void LCD_printFont(uint8_t x, uint8_t y, const unsigned char font, uint8_t size);
extern void Lcd_Draw_Font_8H10W(lcd_t lcd, char * string);
extern void Lcd_Draw_Font_14H17W(lcd_t lcd, char * string);


#endif

